import App from './App'

import { getSDK, CbEvents } from '@openim/client-sdk';
import { createSSRApp } from 'vue'
import mitt from 'mitt'

export function createApp() {
    const app = createSSRApp(App)

    uni.$emitter = mitt();
    uni.$openIM = getSDK();
    
    uni.$openIM.on(CbEvents.OnConnectSuccess, () => {
        console.log('openIM 连接成功');
    });
    uni.$openIM.on(CbEvents.OnSyncServerStart, () => {
        console.log('openIM OnSyncServerStart 事件');
    });
    uni.$openIM.on(CbEvents.OnSyncServerFinish, () => {
        console.log('openIM OnSyncServerFinish 事件');
    });
    uni.$openIM.on(CbEvents.OnSyncServerFailed, () => {
        console.log('openIM OnSyncServerFailed 事件');
    });

    uni.$openIM.on(CbEvents.OnConnecting, () => {
        console.log('openIM OnConnecting 事件');
    });
    uni.$openIM.on(CbEvents.OnConnectFailed, () => {
        console.log('openIM OnConnectFailed 事件');
    });
    uni.$openIM.on(CbEvents.OnConnectSuccess, () => {
        console.log('openIM OnConnectSuccess 事件');
    });
    uni.$openIM.on(CbEvents.OnConversationChanged, (data) => {
        console.log('openIM OnConversationChanged 事件');
        uni.$emitter.emit('OnConversationChanged', data);
    });
    uni.$openIM.on(CbEvents.OnNewConversation, (data) => {
        console.log('openIM OnNewConversation 事件');
        uni.$emitter.emit('OnNewConversation', data);
    });
    uni.$openIM.on(CbEvents.OnRecvNewMessages, (data) => {
        console.log('openIM OnRecvNewMessages 事件');
        uni.$emitter.emit('OnRecvNewMessages', data);
    });
    uni.$openIM.on(CbEvents.OnNewRecvMessageRevoked, (data) => {
        console.log('openIM OnNewRecvMessageRevoked 事件');
        uni.$emitter.emit('OnNewRecvMessageRevoked', data);
    });

    return {
        app
    }
}